package com.stationbuilding.adapter.project;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.stationbuilding.R;
import com.stationbuilding.bean.ProjectBean;
import java.util.List;

public class ProjectListAdapter extends BaseAdapter {
    private List<ProjectBean> list = null;
    private Context mContext;

    public ProjectListAdapter(Context mContext, List<ProjectBean> list) {
        this.mContext = mContext;
        this.list = list;
    }

    /**
     * 当ListView数据发生变化时,调用此方法来更新ListView
     *
     * @param list
     */
    public void updateListView(List<ProjectBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public int getCount() {
        return this.list.size();
    }

    public Object getItem(int position) {
        return list.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        ProjectBean projectBean = list.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.project_item, null);
            viewHolder.projectName = (TextView) convertView.findViewById(R.id.project_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.projectName.setText(projectBean.getProjectName());

        return convertView;
    }

    final static class ViewHolder {
        TextView projectName;
    }
}